package com.lqian.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lqian.pojo.Types;
import com.lqian.service.admin.impl.TypeServiceImpl;

@Controller
@RequestMapping("admin")
public class TypeController {

	@Autowired
	private TypeServiceImpl ti;
	
	@RequestMapping("typeList")
	public String queryAllType(Model model) {
		List<Types> typeList = ti.queryAllType();
		model.addAttribute("typeList",typeList);
		return "type_list.jsp";
	}
	
	@RequestMapping("typeSave")
	public String typeEdit(String name,Integer num) {
		Integer edit = ti.typeEdit(name, num);
		return "redirect:typeList";
	}
	
	@RequestMapping("typeEdit")
	public String findById(Integer id,Model model) {
		Types type = ti.queryById(id);
		model.addAttribute("type", type);
		return "type_edit.jsp";
	}
	
	@RequestMapping("typeUpdate")
	public String typeUpdate(Integer id, String name, Integer num) {
		Integer type = ti.UpdateType(id, name, num);
		return "redirect:typeList";
	}
	
	@RequestMapping("typeDelete")
	public String typeDelete(Integer id) {
		Integer byId = ti.deleteById(id);
		return "redirect:typeList";
	}
	
}
